let { isObject } = require("./index.js");
const handleDataToOne = (initialData) => {
  if (!isObject(initialData)) return;
  let resultData = [];

  const getTargetKey = (data) => {
    if (!isObject(data)) return;
    let tempObj = {};
    // 最终生成的数据简单格式处理
    // let targeKeys = ["type", "content", "nodeId", "outgoing", "prevId"];
    // targeKeys.forEach((i) => {
    //   if (data[i]) {
    //     tempObj[i] = data[i] || undefined;
    //   }
    // });
    tempObj = data;
    if (isObject(tempObj)) resultData.push(tempObj);
    // 递归
    if (data.childNode) {
      getTargetKey(data.childNode);
    }
    if (data.conditionNodes && data.conditionNodes.length) {
      data.conditionNodes.forEach((k) => {
        getTargetKey(k);
      });
    }
  };
  getTargetKey(initialData);
  return resultData;
};

module.exports = {
  handleDataToOne,
};
